<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible"content="IE=8"><!--以IE8模式渲染-->
	<meta http-equiv="X-UA-Compatible"content="IE=7"><!--以IE7模式渲染-->
	<meta http-equiv="X-UA-Compatible"content="IE=9; IE=8; IE=7; IE=EDGE">
	<title>百朋后台管理系统</title>
	<link rel="stylesheet" type="text/css" href="__PUBLIC__/css/manage.css" >
	<link rel="stylesheet" type="text/css" href="__PUBLIC__/easyui/themes/default/easyui.css">
	<link rel="stylesheet" type="text/css" href="__PUBLIC__/easyui/themes/icon.css">
	<link rel="stylesheet" type="text/css" href="__PUBLIC__/easyui/demo.css">
	<link rel="stylesheet" type="text/css" href="__PUBLIC__/js/jquery.alert.v1.2/jquery.alert.css"/>
	<script type="text/javascript" src="__PUBLIC__/js/easyuiTab/jquery-1.4.4.min.js"></script>
	<script type="text/javascript" src="__PUBLIC__/js/jquery.alert.v1.2/jquery.alert.js"></script>  
	<script type="text/javascript" src="__PUBLIC__/js/ajax.js"></script>
	<script TYPE="text/javascript" src="__PUBLIC__/js/common.js"></script>
	<script TYPE="text/javascript" src="__PUBLIC__/js/jquery-1.8.0.min.js"></script>
	<script type="text/javascript" src="__PUBLIC__/easyui/jquery.min.js"></script>
	<script type="text/javascript" src="__PUBLIC__/easyui/jquery.easyui.min.js"></script>

	<style type="text/css">
		.input 
		{
			border: 1px solid #eaeaea;
			background-color: #6d654e;
			color: #fff;
			text-align: center;
			padding: 0px 10px -1px;
			border-radius: 4px;
		}
	</style>
</head>
<body>
	<div class="contentPage">
		<h1>日志详情</h1>
		<table class="list" cellspacing="0" cellpadding="0">
			<tr>
				<td>商户简称</td>
				<td><?php echo $data['visitlog_name']; ?></td>
				<td>拜访方式</td>
				<td><?php echo $data['visitlog_type']; ?></td>
				<td>拜访次数</td>
				<td><?php echo $data['count']; ?></td>
			</tr>

			<tr>
				<td>商户服务类型</td>
				<td><?php echo $data['businesstype_name']; ?></td>
				<td>商户所属商圈</td>
				<td><?php echo $data['circle_name']; ?></td>
				<td>商户地址</td>
				<td><?php echo $data['visitlog_address']; ?></td>
			</tr>

			<tr>
				<td>联系人</td>
				<td><?php echo $data['visitlog_person']; ?></td>
				<td>联系电话</td>
				<td><?php echo $data['visitlog_phone']; ?></td>
				<td>创建时间</td>
				<td><?php echo date('Y-m-d', $data['create_time']); ?></td>
			</tr>

			<tr>
				<td>商务代表</td>
				<td><?php echo $data['user_name']; ?></td>
				<td>商务代表电话</td>
				<td><?php echo $data['user_phone']; ?></td>
				<td>更新时间</td>
				<td><?php echo date('Y-m-d', $data['update_time']); ?></td>
			</tr>

			<tr>
				<td>商户状态</td>
				<td><?php echo $data['mark']; ?></td>
				<td>变更状态</td>
				<td>
					<?php
						if ($data['visitlog_mark'] == '0') 
						{
					?>
					<input type='button' value='跟进商户' onclick="visitlog_del(<?php echo $data['visitlog_id'] ?>)"; />
					<?php
						}
						elseif ($data['visitlog_mark'] == '1') 
						{
					?>
					<input type='button' value='淘汰商户' onclick="visitlog_del(<?php echo $data['visitlog_id'] ?>)"; />
					<?php
						}
						else
						{
							echo "--";
						}
					?>
				</td>
				<?php
					if ($data['visitlog_mark'] == '1') 
					{
				?>
				<td>待审核资料</td>
				<td>
					<input type="button" value="编辑" class="input" onclick="checkinfo_edit('<?php echo $data['visitlog_id'] ?>');">
					<?php
						if ($data['shopby_table'] == '1') 
						{
					?>
					<input type='button' value='提交审核' onclick="check_submit(<?php echo $data['visitlog_id'] ?>)"; />
					<?php
						}
					?>
				</td>
				<?php
					}
					else
					{
						echo '<td>待审核资料</td>';
						echo '<td>--</td>';
					}
				?>
			</tr>
		</table><br/>
		<HR width="100%" color=black /><br/>

		<div class="table_detail">
			<table id="table_detail" class="easyui-datagrid" title="拜访记录" style="width:100%;height:auto" 
				data-options="
					rownumbers:false,
					iconCls: 'icon-edit',
					singleSelect:true,
					toolbar: '#tb',
					autoRowHeight:false,
					onDblClickRow: onClickRow,
					pagination:true,
					pageSize:10
				"
			>
				<thead>
					<tr>
						<th field="key" width="10%" align="center">拜访次数</th>
						<th field="visitlogdetail_returntasktrue" width="15%" align="center" data-options="editor:{type:'textbox',options:{required:true,missingMessage:'此项不能为空'}}">回访任务</th>
						<th field="create_time" width="10%" align="center" data-options="editor:{type:'datebox',options:{formatter:myformatter,parser:myparser,required:true,editable:false,missingMessage:'此项不能为空'}}">回访时间</th>
						<th field="visitlogdetail_person" width="10%" align="center" data-options="editor:{type:'textbox',options:{required:true,missingMessage:'此项不能为空'}}">商户负责人</th>
						<th field="visitlogdetail_phone" width="10%" align="center" data-options="editor:{type:'numberbox',options:{validType:'length[1,11]',invalidMessage:'请填写正确的联系电话',required:true,missingMessage:'此项不能为空'}}">联系电话</th>
						<th field="visitlogdetail_result" width="20%" align="center" data-options="editor:{type:'textbox',options:{required:true,missingMessage:'此项不能为空'}}">拜访结果</th>
						<th field="visitlogdetail_returndate" width="10%" align="center" data-options="editor:{type:'datebox',options:{formatter:myformatter,parser:myparser,required:true,editable:false,missingMessage:'此项不能为空'}}">预计回访日期</th>
						<th field="visitlogdetail_returntask" width="17%" align="center" data-options="editor:{type:'textbox',options:{required:true,missingMessage:'此项不能为空'}}">预计回访任务</th>
					</tr>
				</thead>
			</table>
			<?php
				if ($data['visitlog_mark'] == '1') 
				{
			?>
			<div id="tb" style="height:auto">
				<div style="margin-bottom:5px">
					<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true" onclick="append()">新增</a>
					<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-save',plain:true" onclick="accept()">保存</a>
					<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-undo',plain:true" onclick="reject()">取消</a>
				</div>
			</div>
			<?php
				}
			?>
		</div>
		<br/>
		<HR width="100%" color=black /><br/>
	</div>

	<script type="text/javascript">
		$(function() 
		{
			var json = '{$json_data}';
			var array = JSON.parse(json);
			$('#table_detail').datagrid({loadFilter:pagerFilter}).datagrid('loadData', array);
		});

		var editIndex = undefined;
		function endEditing() 
		{
			if (editIndex == undefined){return true}
			if ($('#table_detail').datagrid('validateRow', editIndex)) 
			{
				$('#table_detail').datagrid('endEdit', editIndex);
				editIndex = undefined;
				return true;
			}
			else
			{
				return false;
			}
		}

		//	新增
		function append() 
		{
			if (endEditing()) 
			{
				$('#table_detail').datagrid('appendRow',{visitlog_id:"<?php echo $data['visitlog_id'] ?>"});
				editIndex = $('#table_detail').datagrid('getRows').length-1;
				$('#table_detail').datagrid('selectRow', editIndex).datagrid('beginEdit', editIndex);
			}
		}

		//	双击编辑
		function onClickRow(index) 
		{
			if (editIndex != index) 
			{
				if (endEditing()) 
				{
					$('#table_detail').datagrid('selectRow', index).datagrid('beginEdit', index);
					editIndex = index;
				}
				else
				{
					$('#table_detail').datagrid('selectRow', editIndex);
				}
			}
		}

		//	保存
		function accept() 
		{
			if (endEditing()) 
			{
				var rowstr = $("#table_detail").datagrid('getChanges');
				var url = "../../facilitator/visitlog/visitlogdetail_add";
				$.ajax({
					type: "POST",
					async: true,
					data: {"addData":rowstr},
					url: url,
					success: function(d) 
					{
						$("#table_detail").datagrid('acceptChanges');
						window.location.reload();
					},
					error: function(e) 
					{
						alert(e);
					}
				});
			}
		}

		//	取消
		function reject() 
		{
			$('#table_detail').datagrid('rejectChanges');
			editIndex = undefined;
		}

		//	商户淘汰动作
		function visitlog_del(visitlog_id) 
		{
			<?php
				if ($data['visitlog_mark'] == '0') 
				{
			?>
			var msg = "您真的确定要继续跟进该商户吗？\n\n请确认！";
			<?php
				}
				elseif ($data['visitlog_mark'] == '1') 
				{
			?>
			var msg = "您真的确定要淘汰该商户吗？\n\n请确认！";
			<?php
				}
			?>
			
			if (confirm(msg)==true) 
			{
				var url = "../../facilitator/visitlog/visitlog_del";
				$.ajax({
					type: "POST",
					async: true,
					data: {"delData":visitlog_id},
					url: url,
					success: function(d) 
					{
						if (d == 1) 
						{
							window.location.reload();
						}
						else
						{
							alert('操作失败，请尝试重新操作或联系管理员！');
							window.history.back(); 
						}
					},
					error: function(e) 
					{
						alert(e);
					}
				});
			}
			else
			{
				return false;
			}
		}

		//	提交审核动作
		function check_submit(visitlog_id) 
		{
			var msg = "您确定要提交该商户资料至风控审核吗？\n\n请确认！";
			if (confirm(msg)==true) 
			{
				var url = "../../facilitator/visitlog/check_submit";
				$.ajax({
					type: "POST",
					async: true,
					data: {"submit":visitlog_id},
					url: url,
					success: function(d) 
					{
						if (d == 1) 
						{
							window.location.reload();
						}
						else
						{
							alert('操作失败，请尝试重新操作或联系管理员！');
							window.history.back(); 
						}
					},
					error: function(e) 
					{
						alert(e);
					}
				});
			}
			else
			{
				return false;
			}
		}

		function checkinfo_edit(visitlog_id) 
		{
			window.parent.addTab('审核资料编辑','../../facilitator/visitlog/visitlog_checkinfo?visitlog_id='+visitlog_id);
		}
	</script>
</body>
</html>